var productId;
window.onload = function () {
    productId = getQuery("id");
    init();
};
async function init() {
    var productInfo = await ajaxGet("/product/findById",{
        id:productId
    });

    $("productImg").src = "/html/img/"+productInfo.imgPath;
    $("productName").innerHTML = productInfo.productName;
    $("productPrice").innerHTML = productInfo.productPrice;
    $("productAddress").innerHTML = productInfo.productAddress;
    $("productTime").innerHTML = productInfo.productTime;
    $("productNum").innerHTML = productInfo.num;
}

async function buy() {
    var info = await ajaxGet("/shop/add",{
        productId:productId
    });
    if (info == "ok"){
        location.href = "/html/custom/shop.html";
    }else {
        alert("添加购物车失败, 请重试")
    }
}

function back() {
    location.href = "/html/index.html"
}